<template>
  <div class="van-multi-picker">
    <div class="van-multi-picker-header">
      <van-button style="border: none; color: #888" @touchstart.stop="onCancel"
        >取消</van-button
      >
      <van-button style="border: none; color: #0571b0" @touchstart.stop="handleClickOk"
        >确定</van-button
      >
    </div>
    <div class="van-multi-picker-content">
      <van-checkbox-group v-model="value">
        <van-cell v-for="item in columns" :key="item.value" :title="item.text">
          <template #right-icon>
            <van-checkbox :name="item.value" />
          </template>
        </van-cell>
      </van-checkbox-group>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps, toRefs } from 'vue'
import { map } from 'lodash'
const value = ref([])

const props = defineProps(['onCancel', 'onConfirm', 'columns'])
const { onCancel, onConfirm, columns } = toRefs(props)

const handleClickOk = () => {
  const objValue = map(value.value, (item) => {
    return columns.value.find((column) => column.value === item)
  })
  onConfirm.value(objValue)
  onCancel.value()
}
</script>

<style lang="scss" scoped>
.van-multi-picker {
  &-header {
    height: 44px;
    line-height: 44px;
    display: flex;
    justify-content: space-between;
  }
}
</style>
